home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / graphics / bgires.zip / DEMO.PAS < prev   
Pascal/Delphi Source File  |  1992-07-11  |  3KB  |  115 lines

  1. program demo;
  2.  
  3. { Program to demonstrate use of BGIRES unit. }
  4.  
  5. { WARNING:  this program should be compiled to disk, not run from memory in
  6.             the IDE.  If you ignore this warning, it may write to TURBO.EXE. }
  7.  
  8.  { The first time you run it, you need to give the path to your BGI files.
  9.  It'll load the one it needs, and after that it won't need the separate BGI
  10.  files any more, unless you switch graphics boards. }
  11.  
  12. uses objects,graph,crt,   { These are the standard Borland units }
  13.      bgires;              { The thing we're demoing! }
  14.  
  15. procedure DrawPicture;
  16. { A silly ad for BGIRES; hit any key to stop it.}
  17. const
  18.   colour : array[0..1] of integer = (Black, White);
  19.   count = 200;
  20. var
  21.   i : integer;
  22.   width, xwidth, ywidth, x, y : word;
  23.   xvel, yvel, xpos, ypos, yaccel,decel : real;
  24.   msg : string;
  25. begin
  26.   xwidth := getmaxx;
  27.   ywidth := getmaxy;
  28.   msg := 'BGIRES';
  29.   settextstyle(defaultfont, horizdir, 2);
  30.   width := textwidth(msg);
  31.   xpos := 0.1 + random*0.9;
  32.   ypos := 1;
  33.   repeat
  34.     xvel := (random-0.5)*0.003;
  35.   until abs(xvel) > 0.0005;
  36.   yvel := 0;
  37.   yaccel := -0.001+random*0.0005;
  38.   decel := (1+random)/2;
  39.   colour[0] := random(16);
  40.   repeat
  41.     setcolor(colour[trunc(random*1.05)]);
  42.     x := trunc(xpos*xwidth) - width div 2;
  43.     y := trunc((1-ypos)*ywidth);
  44.     outtextxy(x,y, msg);
  45.     xpos := xpos + xvel;
  46.     ypos := ypos + yvel;
  47.     yvel := yvel + yaccel;
  48.     if ypos < 0 then
  49.     begin
  50.       ypos := 0;
  51.       yvel := -yvel*decel;
  52.     end;
  53.   until keypressed or (xpos < 0) or (xpos > 1 ) ;
  54. end;
  55.  
  56. var
  57.   res : TResourceFile2;   { New resource file type that can pack itself }
  58.   graphdriver,graphmode:integer;
  59.   i : integer;
  60.   k : char;
  61. begin
  62.  
  63.   { First, open the executable as the resource file.  It'll be empty on
  64.     the first run. }
  65.  
  66.   res.init(New(PBufStream, Init(paramstr(0),stOpen, 1024)));
  67.   if res.stream^.status <> stOK then
  68.     halt(99);
  69.   writeln('Initial size of ',paramstr(0),'=',res.stream^.getsize);
  70.  
  71.   if res.count = 0 then
  72.   begin
  73.     { Put all bgi drivers into the .EXE }
  74.     writeln('Storing all drivers from path "',paramstr(1),'"');
  75.     if putalldrivers(paramstr(1),res,false) <> 0 then
  76.     begin
  77.       writeln('Warning:  Some drivers not stored!');
  78.       writeln('SYNTAX:  DEMO bgipath');
  79.       writeln(' where bgipath is a path (terminated with a "\") to the .BGI files');
  80.     end;
  81.     writeln('   After adding drivers, size=',res.stream^.getsize);
  82.   end;
  83.   res.flush;
  84.   { and then take out all of them except the one we'll need. }
  85.   DetectGraph(graphdriver,graphmode);
  86.   for i:=1 to 10 do
  87.     if drivernum[i] <> drivernum[graphdriver] then
  88.       DelDriver(i,res);
  89.  
  90.   res.pack;            { Now pack to release the deleted space }
  91.  
  92.   writeln('After packing resources, size=',res.stream^.getsize);
  93.   writeln('Hit any key to continue...');
  94.   while keypressed do k:=readkey;
  95.   repeat until keypressed;
  96.   while keypressed do k:=readkey;
  97.  
  98.   { A better way to do the above would be to use the graphdriver value
  99.     to pick the correct driver out of Drivernames, e.g.
  100.       PutDriver(paramstr(1)+ DriverName[DriverNum[GraphDriver]],
  101.                 res, true);
  102.     but I wanted to demonstrate DelDriver and PackResources. }
  103.  
  104.   graphdriver := detect;
  105.   resinitgraph(graphdriver,graphmode,res,'');
  106.  
  107.   randomize;
  108.   repeat
  109.     DrawPicture
  110.   until keypressed;
  111.   closegraph;
  112.  
  113.   res.done;
  114. end.
  115.